package com.kgc.ljp.chapter02.demo04;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Time {
    public static void main(String[] args) {
        final Timer timer = new Timer();
        //结束时间
        final long end = System.currentTimeMillis()+1000*20;
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                long show = end-System.currentTimeMillis();
                System.out.println(show/1000);
            }
        },0,1000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                timer.cancel();
            }
        },new Date(end));
    }
}
